#include "spinboxdelegate.h"

SpinBoxDelegate::SpinBoxDelegate( QObject * parent)
    : QItemDelegate(parent)
{
}

QWidget * SpinBoxDelegate::createEditor( QWidget * parent,
                                         const QStyleOptionViewItem &,
                                         const QModelIndex & ) const
{
QSpinBox * editor = new QSpinBox(parent);
bool ok = true;
editor->setAccelerated(ok);
editor->setButtonSymbols( QAbstractSpinBox::PlusMinus );
editor->setMinimum(40);
editor->setMaximum(900);
editor->installEventFilter( const_cast<SpinBoxDelegate *>(this) );
return editor;
}

void SpinBoxDelegate::setEditorData( QWidget * editor,
                                     const QModelIndex & index ) const
{
    if ( index.model() == NULL )
    {
    return;
    }
int value = index.model()->data(index, Qt::DisplayRole).toInt();
QSpinBox * spinBox = static_cast<QSpinBox *>(editor);
spinBox->setValue(value);
}

void SpinBoxDelegate::setModelData( QWidget * editor,
                                    QAbstractItemModel * model,
                                    const QModelIndex & index) const
{
QSpinBox * spinBox = static_cast<QSpinBox *>(editor);
spinBox->interpretText();
int value = spinBox->value();
model->setData(index, value);
}

void SpinBoxDelegate::updateEditorGeometry( QWidget * editor,
                                            const QStyleOptionViewItem & option,
                                            const QModelIndex & ) const
{
editor->setGeometry(option.rect);
}
